DNS configuration

DNS (Domain Name System) translates human-readable domain names (like example.com) into IP addresses that your system can use to connect to servers. On UNIX/Linux, DNS settings are usually configured in /etc/resolv.conf.

Viewing DNS Configuration

Viewing your current DNS servers can be done through cat /etc/resolv.conf. As you may recall from the Terminal Basics page, the cat command prints the contents of a file into the shell.

shellsession
user@machine:/$ cat /etc/resolv.conf
nameserver 10.255.255.254

Setting DNS temporarily

You can temporarily change the DNS by editing /etc/resolv.conf directly. You will require root, or sudo permissions for this.

shellsession
user@machine:/$ sudo nano /etc/resolv/conf

Once in the nano TUI, you may add nameserver <yourdnsserver> as a line. Once you save and exit nano, the changes will take effect immediately but will reset on reboot or network restart.

Using systemd-resolve (if available)

Some modern Linux Systems use systemd-resolved. Note that this may not come built into linux. Ensure you have this CLI tool present by running systemd-resolve. If it not present, utilize the /etc/resolv.conf method.

You can check your current DNS with the following command:

shellsession
user@machine:/$ systemd-resolve --status

Change DNS temporarily for a specific interface via:

shellsession
user@machine:/$ sudo systemd-resolve --interface eth0 --set-dns <yourdnsserver>

Testing DNS

Check if DNS resolution works using ping or dig(if installed).

shellsession
user@machine:/$ ping example.com
PING example.com (104.18.27.120) 56(84) bytes of data.
64 bytes from 104.18.27.120: icmp_seq=1 ttl=55 time=8.29 ms
64 bytes from 104.18.27.120: icmp_seq=2 ttl=55 time=7.93 ms
shellsession
user@machine:/$ dig example.com # I'd personally recommend just using ping as this is harder to read.

; <<>> DiG 9.20.11-4+b1-Debian <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50850
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;example.com.                   IN      A

;; ANSWER SECTION:
example.com.            300     IN      A       104.18.26.120
example.com.            300     IN      A       104.18.27.120

;; Query time: 11 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) (UDP)
;; WHEN: Mon Mar 02 21:02:37 +08 2026
;; MSG SIZE  rcvd: 72

Summary